// pages/recording/dalyily.js
import { saveDiary } from '../../api/record';
import { dataStr } from '../../utils/date'
const date = `${new Date().getMonth()+1}月${new Date().getDate()}日`;
import Dialog from '../../miniprogram_npm/@vant/weapp/dialog/dialog';
import Toast from '../../miniprogram_npm/@vant/weapp/toast/toast';
let app =  getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    date:date,
    weekIndex:new Date().getDay(),
    week:['星期一','星期二','星期三','星期四','星期五','星期六',,'星期日'],
    diary_title:'',
    diary_content:'',
    navbarData: {
      showCapsule: 1, //是否显示左上角图标   1表示显示    0表示不显示
      title: '日记', //导航栏 中间的标题
      white: false, // 是就显示白的，不是就显示黑的。
    },
    height: app.globalData.height * 2
  },
  save(){

    // wx.navigateTo({url:'allDaylily'})
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(dataStr)
  },

  handelInput(e){
    this.setData({diary_title:e.detail.value})
  },

  handelText(e){
    this.setData({diary_content:e.detail.value})
  },

  save(){
    let time = dataStr.replace(/\//g,'-');
    let diary_content = this.data.diary_content;
    let diary_title = this.data.diary_title;
    saveDiary({diary_title,diary_content,time})
      .then(res=>{
        let { State } = res
        if(State){
          Dialog.confirm({
            title:'提示',
            message: '保存成功,是否前往日记列表查看？',
          }).then(() => {
            // on close
            wx.navigateTo({url:'allDaylily'})
          })
          .catch(()=>{

          });
        }else{
          Toast.fail('保存失败，请重试')
        }
      })
  }
})